package com.kaiupup.study.controller;

import com.kaiupup.study.dto.ResponseResult;
import com.kaiupup.study.request.VerificationCodeDTO;
import com.kaiupup.study.service.VerificationcodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @projectName: kaiupup-online-taxi
 * @package: com.kaiupup.study.controller
 * @className: VerificationCodeController
 * @author: kaiupup
 * @description: TODO
 * @date: 2024/1/12 14:51
 * @version: 1.0
 */

@RestController
@Slf4j
public class VerificationCodeController {

    @Autowired
    private VerificationcodeService verificationcodeService;

    /*
    * 生成验证码
    * */
    @PostMapping("/verificationCode")
    public ResponseResult verificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        System.out.println("verificationCodeDTO = " + verificationCodeDTO);
        return verificationcodeService.generatorCode(verificationCodeDTO.getPassengerPhone());
    }

    @PostMapping("/verification-code-check")
    public ResponseResult checkVerificationCode(@RequestBody VerificationCodeDTO verificationCodeDTO){
        String passengerPhone = verificationCodeDTO.getPassengerPhone();
        String verificationCode = verificationCodeDTO.getVerificationCode();
        log.info("手机号:{},验证码:{}",passengerPhone,verificationCode);
        return verificationcodeService.checkCode(passengerPhone,verificationCode);
    }

    /*
    * 测试用
    * */
    @GetMapping("/test")
    public ResponseResult test(){
        System.out.println("test");
        return ResponseResult.success("成功啦");
    }

}
